package com.test;

import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

/**
 * Created by zhaopeng on 2/15/17.
 */
public class StaticResult {

    public static void main(String[] args){
        Map<String,List<Integer>> tokenCounter = new HashMap<String, List<Integer>>();
        File file = new File(args[0]);
        BufferedReader reader;

        try{
            reader= new BufferedReader(new FileReader(file));
            String line = null;

            while((line=reader.readLine())!=null){
                String[] tmpArray = line.split(Pattern.quote("\t"));
                String token = tmpArray[0];
                int cover = Integer.parseInt(tmpArray[1]);
                int uncover = Integer.parseInt(tmpArray[2]);

                if(tokenCounter.containsKey(token)) {
                    List<Integer> list = tokenCounter.get(token);
                    list.set(0, list.get(0) + cover);
                    list.set(1, list.get(1) + uncover);
                }else{
                    List<Integer> list = new ArrayList<Integer>();
                    list.add(0);
                    list.add(0);

                    list.set(0,cover);
                    list.set(1,uncover);

                    tokenCounter.put(token,list);
                }
                line = null;
            }
        }catch (IOException e){

        }
        FileWriter writer=null;
        try {
             writer = new FileWriter(args[1]);
            for(String token:tokenCounter.keySet()){
                List<Integer> list = tokenCounter.get(token);
                writer.write(token+"\t"+list.get(0)+"\t"+list.get(1)+"\n");

            }
            writer.close();

        }catch (IOException e){

        }



    }
}
